<!-- 搜索表单 -->
<template>
  <ele-card :body-style="{ paddingBottom: '2px' }">
    <el-form label-width="72px" @keyup.enter="search" inline>
      <el-form-item label="状态" v-if="props.action == 'list'">
        <el-radio-group v-model="form.status" @change="search">
          <el-radio-button label="0" value="">全部</el-radio-button>
          <el-radio-button
            v-for="item in statusList"
            :key="item.id"
            :label="item.title"
            :value="item.title"
          >
            {{ item.title }}
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="所属区域">
        <area-radio v-model="form.area_id" @change="search" />
      </el-form-item>
      <br />
      <el-form-item label="车牌号码">
        <el-input v-model.trim="form.plate_number" />
      </el-form-item>
      <el-form-item label="车队名称">
        <el-input v-model.trim="form.company" />
      </el-form-item>

      <el-form-item label-width="16px">
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
  </ele-card>
</template>

<script setup>
  import { ref } from 'vue';

  import { useFormData } from '@/utils/use-form-data';
  import { pageVehicleStatusList } from '@/api/company';
  import AreaRadio from '@/components/AreaRadio/index.vue';

  const emit = defineEmits(['search']);
  const props = defineProps({
    /** 修改回显的数据 */
    action: {
      type: String,
      default: 'list'
    }
  });

  /** 表单数据 */
  const [form] = useFormData({
    company: '',
    area_id: 0,
    plate_number: '',
    status: '正常'
  });

  /** 状态数据 */
  const statusList = ref([]);
  pageVehicleStatusList({ limit: 99999999 })
    .then((res) => {
      statusList.value = res.list;
    })
    .catch((e) => {
      console.log(e);
    });

  /** 搜索 */
  const search = () => {
    console.log(form);
    emit('search', { ...form });
  };
</script>
